# -*- coding: utf-8 -*- 
from calculator import Calculator
import utility

class Calculator_7Dots(Calculator):
    #12 吻长 14 头长 16体长 17叉长 18全长 23眼径 56尾柄长
    def sort_dots(self):
        self.dots.set_dots( utility.sort_dots(self.dots.get_dots(), 'x') )
    
    def prepare_raw_data(self):
        two_dots = [(1,2) ,(1,4), (1,6), (1,7), (1,8), (2,3), (5,6)]
        
        self.sort_dots()
        ds = self.dots.get_dots()
        
        r = []
        for d in two_dots:
            a,b = d
            distance = utility.xdistanceByPixel(ds[a-1],ds[b-1])
            r.append(distance)
            
        head = ['吻长1－2', '头长1－4', '体长1－6', '叉长1－7', '全长1－8', '眼径2－3', '尾柄长5－6']
        self.result.append([head,])
        self.result.append(r) 
    
    def prepare_title(self):
        self.title += '鱼类体长等7个形态学指标'
          
class Calculator_Fish_Framework(Calculator):
    def sort_dots(self):
        result = [None for i in range(10)]
        
        ds = utility.sort_dots(self.dots.get_dots(), 'x')
        result[1] = ds[0]
        
        r = []
        for i in [1,3,5,8]:
            a = utility.max_by_y(ds[i], ds[i+1])
            b = utility.min_by_y(ds[i], ds[i+1])
            r.append(a)
            r.append(b)
            
        result[0] = r[0]
        result[3] = r[1]     
        result[2] = r[2]
        result[5] = r[3]
        result[4] = r[4]
        result[7] = r[5]
        result[6] = ds[7]
        result[8] = r[6]
        result[9] = r[7]
        
        self.dots.set_dots(result)
        
    def prepare_raw_data(self):
        two_dots = [(1,2) ,(1,3), (1,4), (2,3), (2,4), (3,4), (3,5), (3,6), (4,5), (4,6), (5,6), (5,7), (5,8), (6,7), (6,8), (7,8), (7,9), (7,10), (8,9), (8,10), (9,10)]
        
        self.sort_dots()
        ds = self.dots.get_dots()
        
        head = [] ; r = []
        for d in two_dots:        
            a,b = d
            
            h = "%s--%s"%(str(a), str(b))
            head.append(h)
            
            distance = utility.distanceByPixel(ds[a-1],ds[b-1])
            r.append(distance)
        self.result.append([head,])
        self.result.append(r)        
        
    def prepare_title(self):
        self.title += '鱼类(白鱼类)形态框架数据'

class Calculator_GuiFish_Framework(Calculator):
    def sort_dots(self):
        result = [None for i in range(8)]
        
        ds = utility.sort_dots(self.dots.get_dots(), 'x')
            
        result[0] = ds[0]
        result[1] = ds[1]     
        
        result[2] = utility.min_by_y(ds[2], ds[3])
        result[3] = utility.max_by_y(ds[2], ds[3])
        result[4] = utility.min_by_y(ds[4], ds[5])
        result[5] = utility.max_by_y(ds[4], ds[5])
        result[6] = utility.min_by_y(ds[6], ds[7])
        result[7] = utility.max_by_y(ds[6], ds[7])
        
        self.dots.set_dots(result)
        
    def prepare_raw_data(self):
        two_dots = [(1,3) ,(1,4), (2,3), (3,4), (3,5), (3,6), (4,5), (4,6), (5,6), (5,7), (5,8),(6,7), (6,8), (7,8)]
        
        self.sort_dots()
        ds = self.dots.get_dots()
        
        head = [] ; r = []
        for d in two_dots:        
            a,b = d
            
            h = "%s-%s"%(str(a), str(b))
            head.append(h)
            
            distance = utility.distanceByPixel(ds[a-1],ds[b-1])
            r.append(distance)
        self.result.append([head,])
        self.result.append(r)        
        
    def prepare_title(self):
        self.title += '鱼类(鳜鱼类)形态框架数据'
